import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Label;
import java.awt.TextField;
import java.awt.GridLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import com.toedter.calendar.JDateChooser;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import java.io.*;
import java.util.*;


public class appointment {
	
	private JFrame frame;
	private JTextField locationText;
	private JTextField eventName;
	private JTextArea descriptionText;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					appointment window = new appointment();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
		//question here
		try {
			BufferedWriter bWriter = new BufferedWriter(new FileWriter("test.ics"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * Create the application.
	 */
	public appointment() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		String[] timeStrings = { "Start Time","12:00 AM","12:30 AM","1:00 AM","1:30 AM","2:00 AM","2:30 AM","3:00 AM","3:30 AM","4:00 AM","4:30 AM","5:00 AM","5:30 AM","6:00 AM",
								"6:30 AM","7:00 AM","7:30 AM","8:00 AM","8:30 AM","9:00 AM","9:30 AM","10:00 AM","10:30 AM","11:00 AM","11:30 AM","12:00 PM","12:30 PM","1:00 PM",
								"1:30 PM","2:00 PM","2:30 PM","3:00 PM","3:30 PM","4:00 PM","4:30 PM","5:00 PM","5:30 PM","6:00 PM","6:30 PM","7:00 PM","7:30 PM","8:00 PM","8:30 PM",
								"9:00 PM","9:30 PM","10:00 PM","10:30 PM","11:00 PM","11:30 PM"};
		String[] timeStrings1 = { "End Time","12:00 AM","12:30 AM","1:00 AM","1:30 AM","2:00 AM","2:30 AM","3:00 AM","3:30 AM","4:00 AM","4:30 AM","5:00 AM","5:30 AM","6:00 AM",
								 "6:30 AM","7:00 AM","7:30 AM","8:00 AM","8:30 AM","9:00 AM","9:30 AM","10:00 AM","10:30 AM","11:00 AM","11:30 AM","12:00 PM","12:30 PM","1:00 PM",
								 "1:30 PM","2:00 PM","2:30 PM","3:00 PM","3:30 PM","4:00 PM","4:30 PM","5:00 PM","5:30 PM","6:00 PM","6:30 PM","7:00 PM","7:30 PM","8:00 PM","8:30 PM",
								 "9:00 PM","9:30 PM","10:00 PM","10:30 PM","11:00 PM","11:30 PM"};
		
		frame = new JFrame();
		frame.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 12));
		frame.setBounds(100, 100, 418, 361);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JLabel lblEventName = new JLabel("Event Name:");
		lblEventName.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblStartTime = new JLabel("Start Time:");
		lblStartTime.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblEndTime = new JLabel("End Time:");
		lblEndTime.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblLocation = new JLabel("Location:");
		lblLocation.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblDescriptions = new JLabel("Descriptions:");
		lblDescriptions.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		locationText = new JTextField();
		locationText.setColumns(10);
		
		final JDateChooser dateChooser = new JDateChooser();
		
		final JDateChooser dateChooser_1 = new JDateChooser();
		
		eventName = new JTextField();
		eventName.setColumns(10);
		
		JComboBox comboBox = new JComboBox(timeStrings);
		comboBox.setFont(new Font("Tahoma", Font.PLAIN, 12));
		comboBox.setSelectedIndex(0);
		JComboBox comboBox_1 = new JComboBox(timeStrings1);
		comboBox_1.setFont(new Font("Tahoma", Font.PLAIN, 12));
		comboBox_1.setSelectedIndex(0);
		JButton btnNewButton = new JButton("Create Event");
		
		//eventHandler
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Date startDate = dateChooser.getDate();
				Date endDate = dateChooser_1.getDate();
				
				bWriter.write("BEGIN:VCALENDAR");
				bWriter.newLine();
				bWriter.write("VERSION:1.0");
				bWriter.newLine();
				bWriter.write("BEGIN:VEVENT");
				bWriter.newLine();
				bWriter.write("DTSTART:" + startDate);
				bWriter.newLine();
				bWriter.write("DTEND:" + endDate);
				bWriter.newLine();
				bWriter.write("SUMMARY:" + eventName.getText());
				bWriter.newLine();
				bWriter.write("LOCATION:" + locationText.getText());
				bWriter.newLine();
				bWriter.write("DESCRIPTION:" + descriptionText.getText());
				bWriter.newLine();
				bWriter.write("END:VEVENT");
				bWriter.newLine();
				bWriter.write("END:VCALENDAR");
				bWriter.close();
			}
		});  //end of eventHandler
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		descriptionText = new JTextArea();
		GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(lblEventName)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblStartTime)
								.addComponent(lblDescriptions)
								.addComponent(lblLocation)
								.addComponent(lblEndTime))
							.addGap(18)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addComponent(dateChooser, GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
										.addComponent(dateChooser_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
									.addGap(41)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
										.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)))
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
										.addComponent(locationText, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
										.addComponent(eventName, GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
										.addComponent(btnNewButton)
										.addComponent(descriptionText, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE))
									.addPreferredGap(ComponentPlacement.RELATED)))))
					.addGap(201))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblEventName)
						.addComponent(eventName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(15)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(dateChooser_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblStartTime))
					.addGap(13)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(dateChooser, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEndTime))
					.addGap(11)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblLocation)
						.addComponent(locationText, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
					.addGap(27)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblDescriptions)
						.addComponent(descriptionText, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addComponent(btnNewButton)
					.addGap(84))
		);
		frame.getContentPane().setLayout(groupLayout);
	}
}
